package io.litchi.auth.domain.repository;

import io.litchi.auth.domain.entity.auth.MenuPerm;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 *
 *
 * @author helang
 * @since 2025-11-25
 */
public interface MenuPermRepository extends  JpaRepository<MenuPerm,Long>, JpaSpecificationExecutor<MenuPerm> {

    List<MenuPerm> findAllByStatus(int i);


    @Query("select count(*) from MenuPerm where pid = ?1")
    Long countByPid(Long id);

    @Modifying
    @Query("update MenuPerm set status = ?2 where id = ?1")
    void updateStatusById(@NotNull(message = "未知的菜单") Long id, @Max(value = 1, message = "错误的状态") @Min(value = 0, message = "错误的状态") Integer status);
}